// pages/report/report.js
var request = require("../../utils/request.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: '',
    info: "",
    info1: "",
    s: "0"
  },
  confirmUser: function () {
    var that = this
    that.toastDialog.showDialog({ code: 'loading', message: '加载中', timeout: false }); //loading 加载框

    request.postData('xcx/bindTestEUser', { uid: that.data.uid, tid: that.data.options.tid, type: that.data.options.type }, function (res) {
      // success
      that.toastDialog.hideDialog(); //关闭loading提示框
      if (res.code == '0') {
        that.toastDialog.showDialog({ code: res.code, message: '关联成功', timeout: true });
        wx.navigateBack({
          delta: '1',
        })
      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }

    }, function (res) {
      // error
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      options: options
    })
    console.log(options)
    this.toastDialog = this.selectComponent("#toastDialog");//此处id和页面的 wxml中的id一致
    this.getUserList()
    wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
  },
/**
 * 用户点击右上角分享
 */
onShareAppMessage (res) {
  return {
    title: '迪佳极视',
    path: 'pages/index/index',
    // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
    success: function (shareTickets) {
      console.info(shareTickets + '成功');
      // 转发成功
    },
    fail: function (res) {
      console.log(res + '失败');
      // 转发失败
    },
    complete:function(res){
      // 不管成功失败都会执行
    }
  }
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getUserList: function () {
    var that = this
    that.toastDialog.showDialog({ code: 'loading', message: '加载中', timeout: false }); //loading 加载框

    request.postData('xcx/myUserList', {}, function (res) {
      // success
      that.toastDialog.hideDialog(); //关闭loading提示框
      if (res.code == '0') {
        if (res.userList.length != 0) {
          that.setData({
            userList: res.userList
          })
        } else {
          that.setData({
            info: "空空如也~",
            s: "1"
          })
        }

      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }

    }, function (res) {
      // error
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });
  },
  //chekcbox
  radioChange: function (e) {
    console.log(e)
    var that = this
    
    if(e.detail.value.length>0){
      let arr = that.data.userList
      arr.forEach(function(v,i){
        //console.log(v);
        if(v.id==e.detail.value){
          v.checked=true
        }else{
          v.checked=false
        }
      })
      this.setData({
        uid: e.detail.value,
        userList:arr
      })
    }else{
      this.setData({
        uid: e.detail.value,
      })
    }
  }
})